<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

      <!-- @selection-change="handleSelectionChange" -->
    <el-table v-loading="loading" :data="user_roleList" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="userId" />
      <el-table-column label="头像" align="center" prop="userAvatar" width="250px">
         <!-- 获取图片 -->
        <template slot-scope="scope">
            <el-avatar shape="circle" :size="50" fit="contain" :src="scope.row.userAvatar"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="nickName"/>
      <el-table-column label="性别" align="center" prop="userSex" />
      <el-table-column label="年龄" align="center" prop="userAge" />
      <el-table-column label="身份证号" align="center" prop="userCard" width="280px"/>
      <el-table-column label="邮箱" align="center" prop="userEmail" />
      <el-table-column label="手机号" align="center" prop="userMobile" width="110px"/>
      <el-table-column label="金额" align="center" prop="userAmount" width="110px"/>
      <el-table-column label="实名认证状态" align="center" prop="status" />
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="110px">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            >请前往实名认证</el-button>
        </template>
    </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 实名认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form :model="form">
            <el-form-item label="用户ID:" prop="userMobile">
              <el-input v-model="form.userId"/>
            </el-form-item>
            <el-upload
                class="avatar-uploader"
                action="http://localhost:9401/duanxin/ossUpload"
                :show-file-list="false"
                :on-success="handleAvatarSuccess">
                <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>


        </el-form>
        
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getList } from "@/api/user/user";
import { getSet } from "@/api/user/user";
import { getsetCode } from "@/api/user/user";

export default {
  name: "User_list",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户角色表表格数据
      user_roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        roleId: null,
        status: null,
      },
      // 表单参数
      form: {
        imageUrl: '',
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        userName: null,
        userPass: null,
        nickName: null,
        userCard: null,
        userEmail: null,
        userMobile: null,
        userAge: null,
        userSex: null,
        userAmount: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 查询用户角色表列表 */
    getList() {
      this.loading = true;
      getList(this.queryParams).then(res => {
          console.log('getList',res);
        this.user_roleList = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //  // 多选框选中数据
    //  handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.userRoleId)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
     /** 修改按钮操作 */
     handleUpdate(row) {
      console.log('handleUpdate',row.userId);
      this.form.userId = row.userId;
      this.open = true;
    //   this.reset();
    //   const userId = row.userId || this.ids
    //   getSet(userId).then(res => {
    //     if(res.code == 200) {
    //         console.log('getSet',res);
    //         // this.form = res.data;
    //         this.open = true;
    //         this.title = "修改用户信息表";
    //     }
    //     else{
    //         let msg = res.msg;
    //         this.$message.error(msg);
    //     }
    //   });
    },
     /** 提交按钮 */
     submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            getSet(this.form).then(res => {
              if(res.code == 200){
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
              else{
                let msg = res.msg;
                this.$message.error(msg);
              }
            });
        }
      });
    },
    //图片上传
    handleAvatarSuccess(res) {
        console.log('handleAvatarSuccess',res)
        this.form.imageUrl = res.msg;
        console.log(res.msg)
    },

  }
}
    
</script>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

</style>


